import sys
import numpy as np
import xlrd

def doAnalysis(filename):
    excel_file = xlrd.open_workbook(filename)
    table = excel_file.sheet_by_index(0)
    nrows = table.nrows
    ncols = table.ncols
    title_table = table.row_values(0)

    dataset = []
    gpsset = []

    # 写开头格式
    for i in range(1, nrows):
        gps = []
        data = {}
        for j in range(ncols):
            data[title_table[j]] = table.row(i)[j].value
            if 'longitude' == title_table[j]:
                gps.append(float(table.row(i)[j].value))
            elif 'latitude' == title_table[j]:
                gps.append(float(table.row(i)[j].value))

        gpsset.append(gps)
        dataset.append(data)

    # 去重
    gpsset = np.array(list(set([tuple(t) for t in gpsset])))

    gpsjsonset = []
    for i in range(len(gpsset)):
        gpsjsonset.append({
            'longitude': gpsset[i][0],
            'latitude': gpsset[i][1]
        })

    return gpsjsonset, dataset

if __name__ == '__main__':
    filename = sys.argv[1]
    gpsjsonset, dataset = doAnalysis(filename)
    np.set_printoptions(threshold=sys.maxsize)
    print(gpsjsonset)
